﻿namespace EasyToolkit.BindingTemplates.Definitions
{
    using System;
    using System.Xml.Serialization;

    [XmlRoot("Template")]
    public class TemplateOption
    {
        [XmlAttribute]
        public string Name
        { get; set; }

        [XmlAttribute]
        public string Description
        { get; set; }

        [XmlAttribute]
        public string BindWith
        { get; set; }

        [XmlAttribute]
        public bool SortAndFilter
        { get; set; }

        [XmlIgnore]
        public Orientation Orientation
        { get; set; }

        private string orientationStr;
        [XmlAttribute("Orientation")]
        public string OrientationStr
        {
            get { return orientationStr; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    orientationStr = value.Trim().ToUpper();
                    if (orientationStr.Equals("H") || orientationStr.Equals("HORIZONTAL"))
                        Orientation = Orientation.Horizontal;
                    else if (orientationStr.Equals("V") || orientationStr.Equals("VERTICAL"))
                        Orientation = Orientation.Vertical;
                    else
                        throw new ArgumentException(string.Format("The attribut 'Orientation' '{0}' is invalid. Value must be 'V' or 'Vertical' or 'H', 'Horizontal' (no case sentitive)", value));
                }
            }
        }

        public TemplateOption()
        {
            SortAndFilter = true;
            Orientation = Orientation.Vertical;
        }
    }
}
